<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
    <style type="text/css">
      *:focus {
        background-color: yellow !important;
        color: Black !important;
      }
    </style>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const store = testHelpers.createStore();
        const directLine = WebChat.createDirectLine({ token: await testHelpers.token.fetchDirectLineToken() });

        WebChat.renderWebChat(
          {
            directLine,
            store
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();

        await pageObjects.sendMessageViaSendBox('markdown', { waitForSend: true });
        await pageConditions.minNumActivitiesShown(2);
        await pageConditions.scrollToBottomCompleted();

        await pageObjects.focusTranscript();

        // Select the first activity, this should scroll to the top of the transcript.
        await host.sendKeys('ARROW_UP', 'ARROW_UP');
        await pageConditions.scrollStabilized(0);

        store.dispatch({
          type: 'WEB_CHAT/SEND_MESSAGE',
          payload: {
            text: 'herocard'
          }
        });

        await pageConditions.minNumActivitiesShown(4);
        await pageConditions.scrollToEndButtonShown();

        await pageConditions.allImagesLoaded();

        await host.sendShiftTab();

        // After pressing TAB from transcript, it should focus on the "New messages" button.
        expect(document.activeElement === pageElements.scrollToEndButton()).toBe(true);

        await host.snapshot();
      });
    </script>
  </body>
</html>
